<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class PusherEvent  implements ShouldBroadcast{
    //SerializesModels 可以将public属性的数据序列化
    use Dispatchable, InteractsWithSockets, SerializesModels;

    //(只有)public 属性才会被作为广播的数据
    public $text, $id;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($text, $id)
    {
        //
        $this->text=$text;
        $this->id=$id;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('laravel-broadcast-channel');
    }
}
